// Require `PhoneNumberFormat`.
const PNF = require('google-libphonenumber').PhoneNumberFormat;
let phoneLib = require('google-libphonenumber').PhoneNumberUtil.getInstance();

// Get an instance of `PhoneNumberUtil`.
let p = require('google-libphonenumber');
let ins = p.PhoneNumberUtil.getInstance()
console.log(ins);

const number = ins.parseAndKeepRawInput('+16474830425')
console.log(ins.getRegionCodeForNumber(number))
const number2 = ins.parseAndKeepRawInput('+17272870079')
console.log(ins.getRegionCodeForNumber(number2))

function demo(phone){
    try{
        if(!phone){
            return '';
        }
        if(phone.match(/^00/)){
            phone = phone.replace('00', '+')
        }
        let result = phoneLib.parseAndKeepRawInput(phone);
        return phoneLib.getRegionCodeForNumber(result);
    }catch(err){
        console.log('err', err)
        return 'ERROR'
    }
}

let r= demo('008613401175123')
console.log(r)
//
// console.log(number);
// // Print the phone's country code.
// console.log(number.getCountryCode());
// // => 1
//
// // Print the phone's national number.
// console.log(number.getNationalNumber());
// // => 2024561414
//
// // Print the phone's extension.
// console.log(number.getExtension());
// // =>
//
// // Print the phone's extension when compared to i18n.phonenumbers.CountryCodeSource.
// console.log(number.getCountryCodeSource());
// // => FROM_DEFAULT_COUNTRY
//
// // Print the phone's italian leading zero.
// console.log(number.getItalianLeadingZero());
// // => false
//
// // Print the phone's raw input.
// console.log(number.getRawInput());
//'[iQIYI] رمز التحقق هو 689304 . لحمايتك ، لا تشارك الرمز مع أي شخص آخر

